package com.tts.superstar.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.tts.superstar.R;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class PastFragment extends Fragment {

    List<Map> list;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_past, container, false);
        initData();

        ListView listView = view.findViewById(R.id.lv_three);
        MyAdapter myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);

        return view;
    }

    private void initData() {
        list = new ArrayList<>();
        String[] strings = {"超星杯长三角阅读摄影大赛","【每天30分钟一讲座】刘禹锡","第三届全国共读活动",
                "【每天30分钟一讲座】《庄子》","全国中小学生安全教育日公益活动", "第二届超星杯微文学大赛",
                "超星尔雅-直播系列活动"};
        int[] ints = {R.mipmap.huodong7,R.mipmap.huodong6,R.mipmap.huodong3,R.mipmap.huodong1,R.mipmap.huodong2
                ,R.mipmap.huodong4,R.mipmap.huodong5};
        for(int i = 0; i < 7; i++){
            Map<String,Object> map = new HashMap<>();
            map.put("img",ints[i]);
            map.put("text",strings[i]);
            map.put("time",new Date());
            list.add(map);
        }
    }


    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_abc,parent,false);


            Map<String,Object> map = list.get(position);
            ImageView imageView = convertView.findViewById(R.id.iv_one);
            imageView.setBackgroundResource(Integer.parseInt(map.get("img")+""));

            TextView textView = convertView.findViewById(R.id.tv_two);
            textView.setText(map.get("text")+"");

            TextView textView1 = convertView.findViewById(R.id.tv_three);
            textView1.setText(map.get("time")+"");

            return convertView;
        }
    }

}
